package com.hm.hall.commons.constans;


import com.hm.hall.commons.util.AnnotationDefinitionUtils;
import com.hm.hall.commons.domain.ConsoleConfig;
import org.apache.log4j.Logger;

import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;


/**
 * 运维配置项key常量类
 */
public class ConsoleConfigKeysConstants {

    @AnnotationDefinitionUtils(cnName = "邮箱帐号", showType = "text", Desc = "邮箱帐号", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_MAIL_USERNAME = "GAME_MAIL_USERNAME";
    @AnnotationDefinitionUtils(cnName = "邮箱密码", showType = "text", Desc = "邮箱密码", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_MAIL_PASSWORD = "GAME_MAIL_PASSWORD";
    @AnnotationDefinitionUtils(cnName = "邮箱smtp端口", showType = "text", Desc = "邮箱smtp端口", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_MAIL_HOST = "GAME_MAIL_HOST";
    @AnnotationDefinitionUtils(cnName = "项目域名", showType = "text", Desc = "项目域名", sort = 1, isDisplay = false, group = "system_cfg", cacheSec = 30)
    public final static String GAME_PRODUCT_PUBLIC_IP = "GAME_PRODUCT_PUBLIC_IP";
    @AnnotationDefinitionUtils(cnName = "app 分享说明", showType = "text", cnValue = "", Desc = "app 更新说明", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String APP_SHARE_INFO = "APP_SHARE_INFO";
    /**
     * APP版本号
     */
    @AnnotationDefinitionUtils(cnName = "APP版本号", showType = "text", cnValue = "1.0.109", Desc = "APP版本号-暴露的", sort = 1, group = "系统配置", isExpose = true)
    public final static String APP_VERSION = "APP_VERSION";

    // region ****************************************** 暴露的系统配置 *******************
    // ************************************* 微信APP支付
    @AnnotationDefinitionUtils(cnName = "微信支付APPID", showType = "text", Desc = "微信支付APPID", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_APPID_PAY = "GAME_APPID_PAY";
    @AnnotationDefinitionUtils(cnName = "微信支付 商户号商户ID", showType = "text", Desc = "微信支付 商户号商户ID", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_MCH_ID_PAY = "GAME_MCH_ID_PAY";
    @AnnotationDefinitionUtils(cnName = "微信支付 商户KEY", showType = "text", Desc = "微信支付 商户KEY", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_WEIXINPAY_MCH_KEY = "GAME_WEIXINPAY_MCH_KEY";
    // ************************************* 微信服务号
//	@AnnotationDefinitionUtils(cnName = "微信服务号域名", showType = "text", Desc = "微信服务号域名", sort = 1, isDisplay = false, group = "system_cfg")
//	public final static String GAME_WX_DOMAIN = "GAME_WX_DOMAIN";
    @AnnotationDefinitionUtils(cnName = "微信服务号APPID", showType = "text", Desc = "微信服务号APPID", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_APPID = "GAME_APPID";
    @AnnotationDefinitionUtils(cnName = "微信服务号APPSECRET", showType = "text", Desc = "微信服务号APPSECRET", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_APPSECRET = "GAME_APPSECRET";
    @AnnotationDefinitionUtils(cnName = "微信服务号事件响应的消息", showType = "text", Desc = "微信服务号事件响应的消息内容", cnValue = "{\"subscribe\":\"欢迎关注\",\"unsubscribe\":\"谢谢关注\"}", sort = 2, isDisplay = false, group = "mp_weixin")
    public final static String GAME_MP_WEIXIN_EVENT_MESSAGE_RESP = "GAME_MP_WEIXIN_EVENT_MESSAGE_RESP";
    // *** 微信支付的公众号
    @AnnotationDefinitionUtils(cnName = "微信支付服务号APPID", showType = "text", Desc = "微信支付服务号APPID", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_APPID_MP_PAY = "GAME_APPID_MP_PAY";
    @AnnotationDefinitionUtils(cnName = "支付微信服务号 商户号商户ID", showType = "text", Desc = "支付微信服务号APPSECRET", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_MCH_ID_MP_PAY = "GAME_MCH_ID_MP_PAY";
    @AnnotationDefinitionUtils(cnName = "支付微信公众号商户KEY", showType = "text", Desc = "支付微信公众号商户KEY", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String GAME_WEIXINPAY_MCH_KEY_MP = "GAME_WEIXINPAY_MCH_KEY_MP";
    @AnnotationDefinitionUtils(cnName = "prolong配置", showType = "text", cnValue = "[{\"cfgList\":[{\"amount\":1,\"dealType\":2001},{\"amount\":2,\"dealType\":2011}],\"grade\":1},{\"cfgList\":[{\"amount\":1,\"dealType\":2002},{\"amount\":2,\"dealType\":2012}],\"grade\":2},{\"cfgList\":[{\"amount\":3,\"dealType\":2003},{\"amount\":5,\"dealType\":2013}],\"grade\":3},{\"cfgList\":[{\"amount\":3,\"dealType\":2004},{\"amount\":5,\"dealType\":2014}],\"grade\":4},{\"cfgList\":[{\"amount\":5,\"dealType\":2005},{\"amount\":8,\"dealType\":2015}],\"grade\":5},{\"cfgList\":[{\"amount\":5,\"dealType\":2006},{\"amount\":8,\"dealType\":2016}],\"grade\":6}]", Desc = "prolong配置", sort = 1, cacheSec = 30, isDisplay = false, group = "system_cfg")
    public final static String GAME_PROLONG_CFG = "GAME_PROLONG_CFG";
    @AnnotationDefinitionUtils(cnName = "安卓支付列表", showType = "text", Desc = "安卓支付列表", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String ANDROID_PAY_LIST = "ANDROID_PAY_LIST";
    @AnnotationDefinitionUtils(cnName = "IOS支付列表", showType = "text", Desc = "IOS支付列表", sort = 1, isDisplay = false, group = "system_cfg")
    public final static String IOS_PAY_LIST = "IOS_PAY_LIST";
    @AnnotationDefinitionUtils(cnName = "下载软件二维码", showType = "text", cnValue = "https://pub.froup.net/wepoker/qrcode/qr_code.png", Desc = "下载软件二维码", sort = 1, isDisplay = false, group = "system_cfg", cacheSec = 30)
    public final static String DOWNLOAD_QRCODE = "DOWNLOAD_QRCODE";
    @AnnotationDefinitionUtils(cnName = "大厅服务地址...", showType = "text", cnValue = "", Desc = "大厅服务地址..", sort = 1, group = "系统配置", isExpose = true)
    public final static String HALL_SERVER_BASE_URL = "HALL_SERVER_BASE_URL";
    @AnnotationDefinitionUtils(cnName = "playlog服务地址...", showType = "text", cnValue = "", Desc = "playlog服务地址..", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String PLAYLOG_SERVER_BASE_URL = "PLAYLOG_SERVER_BASE_URL";
    /**
     * 游戏服务器是否在维护中 1:是,0:否
     */
    @AnnotationDefinitionUtils(cnName = "服务器是否在维护", showType = "text", cnValue = "0", Desc = "游戏服务器是否在维护中 1:是,0:否", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String IS_GAME_SERVER_MAINTAIN = "IS_GAME_SERVER_MAINTAIN";
    /**
     * 游戏服务器是否在维护中 1:是,0:否
     */
    @AnnotationDefinitionUtils(cnName = "服务器是否在维护-强制关闭房间", showType = "text", cnValue = "0", Desc = "游戏服务器是否在维护中-强制关闭房间 1:是,0:否", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String IS_CLOSE_GAME_SERVER_MAINTAIN = "IS_CLOSE_GAME_SERVER_MAINTAIN";
    @AnnotationDefinitionUtils(cnName = "收费配置", showType = "text", cnValue = "1", Desc = "收费配置", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String ROOM_PRICE_CFG = "ROOM_PRICE_CFG";
    @AnnotationDefinitionUtils(cnName = "留座离桌是否参与牌局", showType = "text", cnValue = "0", Desc = "留座离桌是否参与牌局", sort = 1, group = "系统配置", cacheSec = 10, isExpose = true)
    public final static String LEAVE_IS_PLAY = "LEAVE_IS_PLAY";
    @AnnotationDefinitionUtils(cnName = "服务器俱乐部测试日志列表", showType = "text", cnValue = "0", Desc = "服务器俱乐部测试日志列表 多个用；隔开", sort = 1, group = "系统配置", cacheSec = 30, isExpose = true)
    public final static String SERVER_CLUB_PRINTF_LOG = "SERVER_CLUB_PRINTF_LOG";
    /**
     * log
     */
    private final static Logger log = Logger.getLogger(ConsoleConfigKeysConstants.class);

    /**
     * 配置信息设置
     *
     * @return Map
     */
    public static Map<Object, ConsoleConfig> getConfigInstance() {
        Map<Object, ConsoleConfig> map = new LinkedHashMap<>();
        Class<ConsoleConfigKeysConstants> classType = ConsoleConfigKeysConstants.class;
        Field[] fields = classType.getDeclaredFields();
        for (Field field : fields) {
            boolean hasAnnotation = field.isAnnotationPresent(AnnotationDefinitionUtils.class);
            if (hasAnnotation) {
                AnnotationDefinitionUtils annotation = field.getAnnotation(AnnotationDefinitionUtils.class);
                ConsoleConfig config = new ConsoleConfig();
                try {
                    Object fieldName = field.get(field.getName());
                    config.setCval(annotation.cnValue());
                    config.setCkey(String.valueOf(fieldName));
                    config.setCnName(annotation.cnName());
                    config.setShowType(annotation.showType());
                    config.setRemarks(annotation.Desc());
                    config.setSort(annotation.sort());
                    config.setCgroup(annotation.group());
                    map.put(fieldName, config);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    log.error(e);
                }
            }
        }
        return map;
    }

    public static AnnotationDefinitionUtils getAnnotationDefinitionUtilsByKey(String key) {
        Class<ConsoleConfigKeysConstants> classType = ConsoleConfigKeysConstants.class;
        try {
            Field field = classType.getField(key);
            return field.getAnnotation(AnnotationDefinitionUtils.class);
        } catch (NoSuchFieldException ignored) {
            return null;
        }
    }

}
